<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import * as echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
// import resize from "./mixins/resize";
export default {
  // mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "400px",
    },
    companySectorList: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      chart: null,
    };
  },
  // created() {
  //   this.initChart();
  // },
  computed: {
    // 名字
    companySectorName() {
      return this.companySectorList.map(item => item.name)
    },
    // 数量
    companySectorCount() {
      return this.companySectorList.map(item => item.count)
    },
  },
  watch: {
    companySectorList(newVal, oldVal) {
      if (newVal.length > 0) {
        this.initChart();
      }
    },
  },
  mounted() {
    this.initChart();
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");
      const that = this;
      this.chart.setOption({
        title: {
          text: "求职者申请职位企业行业流向",
          left: "",
          textStyle: {
            color: "#333", // 字体颜色设置为黑色
            fontWeight: "bold", // 加粗字体
          },
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        // legend: {
        //   data: ["男", "女"],
        //   top: 30,
        // },
        xAxis: {
          type: "category",
          data:this.companySectorName,
          axisLabel: {
            color: "#333",
          },
        },
        yAxis: {
          type: "value",
          max: 500,
          axisLabel: {
            color: "#333",
          },
        },
        series: [
          {
            name: "流入",
            type: "bar",
            data:this.companySectorCount,
            itemStyle: { color: "#5B8FF9" },
          },
        ],
      });
    },
  },
};
</script>

<style scoped></style>
